package org.song.controller;

import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.song.exception.result.AjaxResult;
import org.song.model.dto.ThumbsUpDto;
import org.song.model.vo.ThumbsUp;
import org.song.service.ThumbsUpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 博客点赞控制层
 */
@Api(tags = "博客点赞控制层")
@Controller
@RequestMapping(value = "/thumbsUp")
public class ThumbsUpController {

    @Autowired( required = true )
    @Qualifier( value = "thumbsUpServiceImpl")
    private ThumbsUpService thumbsUpService;

    /**
     * 查询所有的博客点赞
     * @param thumbsUpDto
     * @return
     */
    @ApiOperation(value = "查询所有的博客点赞" , notes = "查询所有的博客点赞")
    @ResponseBody
    @RequestMapping(value = "/listThumbsUps" , method = RequestMethod.GET)
    public AjaxResult<List<ThumbsUp>> listThumbsUps(@ApiParam(value = "thumbsUpDto实例接受查询参数") @NonNull ThumbsUpDto thumbsUpDto) {
        PageHelper.startPage(thumbsUpDto.getPage() , thumbsUpDto.getSize());
       return AjaxResult.success(thumbsUpService.listThumbsUps(thumbsUpDto));
    }

    /**
     * 删除博客点赞
     * @param thumbsUp
     * @return
     */
    @ApiOperation(value = "删除博客点赞" , notes = "删除博客点赞")
    @ResponseBody
    @RequestMapping(value = "/deleteThumbsUp" , method = RequestMethod.DELETE)
    public AjaxResult<Integer> deleteThumbsUp(@ApiParam(value = "接受需要删除的博客点赞") @NonNull @RequestBody ThumbsUp thumbsUp) {
        return AjaxResult.success(thumbsUpService.deleteThumbsUp(thumbsUp));
    }

    /**
     * 增加博客点赞
     * @param thumbsUp
     * @return
     */
    @ApiOperation(value = "增加博客点赞" , notes = "增加博客点赞")
    @ResponseBody
    @RequestMapping(value = "/insertThumbsUp" , method = RequestMethod.PUT)
    public AjaxResult<Integer> insertThumbsUp(@ApiParam(value = "博客点赞") @NonNull @RequestBody ThumbsUp thumbsUp) {
        return AjaxResult.success(thumbsUpService.insertThumbsUp(thumbsUp));
    }

    /**
     * 更新博客点赞
     * @param thumbsUp
     * @return
     */
    @ApiOperation(value = "更新博客点赞" , notes = "更新博客点赞")
    @ResponseBody
    @RequestMapping(value = "/updateThumbsUp" , method = RequestMethod.POST)
    public AjaxResult<Integer> updateThumbsUp(@ApiParam(value = "根据传入的点赞信息进行博客点赞更新") @NonNull @RequestBody ThumbsUp thumbsUp) {
        return AjaxResult.success(thumbsUpService.updateThumbsUp(thumbsUp));
    }


}
